package com.bluefish.bltuan.module.cms;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;

@Entity(name="CMS")
public class Content implements Serializable{


	/**
	 * 
	 */
	private static final long serialVersionUID = 4548176844028259243L;

	private static final String HTTP = "http://";

	private static final String SLASH = "/";

	@Id
	@GeneratedValue
	private Integer id;
	
	@Enumerated
	private ContentType type;
	
	private String title;
	
	@Lob
	private String content;
	
	private String nick;
	
	private int position;
	
	private boolean link;
	
	private String website;
	
	private Date lastModified;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public ContentType getType() {
		return type;
	}

	public void setType(ContentType type) {
		this.type = type;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}

	public String getNick() {
		return nick;
	}

	public void setNick(String nick) {
		this.nick = nick;
	}

	public int getPosition() {
		return position;
	}

	public void setPosition(int position) {
		this.position = position;
	}

	public boolean isLink() {
		return link;
	}

	public void setLink(boolean link) {
		this.link = link;
	}

	public String getWebsite() {
		return website;
	}

	public void setWebsite(String website) {
		this.website = website;
		if(!isHttp() && !website.startsWith(SLASH))
			this.website = SLASH + this.website;
	}

	public Date getLastModified() {
		return lastModified;
	}

	public void setLastModified(Date lastModified) {
		this.lastModified = lastModified;
	}
	
	public boolean isHttp(){
		return this.link && this.website != null
			&& this.website.startsWith(HTTP);
	}
	
	public String getUrl(){
		if(link){
			return website;
		}else
			return SLASH + nick;
	}
}
